home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / ltp_bitmap.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  3KB  |  153 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <exec/memory.h>
  17.  
  18. /*****************************************************************************/
  19.  
  20. #include "Assert.h"
  21.  
  22. /*****************************************************************************/
  23.  
  24. struct FatBitMap
  25. {
  26.     struct BitMap    BitMap;
  27.     LONG            Width;
  28.     LONG            Height;
  29. };
  30.  
  31. /*****************************************************************************/
  32.  
  33. LONG
  34. LTP_GetDepth(struct BitMap *BitMap)
  35. {
  36.     if(V39)
  37.         return((LONG)GetBitMapAttr(BitMap,BMA_DEPTH));
  38.     else
  39.         return(BitMap->Depth);
  40. }
  41.  
  42. VOID
  43. LTP_DeleteBitMap(struct BitMap *BitMap,BOOL Chip)
  44. {
  45.     if(V39 && !Chip)
  46.         FreeBitMap(BitMap);
  47.     else
  48.     {
  49.         if(BitMap)
  50.         {
  51.             struct FatBitMap *Fat;
  52.             LONG i;
  53.  
  54.             Fat = (struct FatBitMap *)BitMap;
  55.  
  56.             if(Fat->Width && Fat->Height)
  57.             {
  58.                 for(i = 0 ; i < BitMap->Depth ; i++)
  59.                     FreeRaster(BitMap->Planes[i],Fat->Width,Fat->Height);
  60.             }
  61.             else
  62.             {
  63.                 for(i = 0 ; i < BitMap->Depth ; i++)
  64.                     FreeVec(BitMap->Planes[i]);
  65.             }
  66.  
  67.             FreeVec(BitMap);
  68.         }
  69.     }
  70. }
  71.  
  72. struct BitMap *
  73. LTP_CreateBitMap(LONG Width,LONG Height,LONG Depth,struct BitMap *Friend,BOOL Chip)
  74. {
  75.     struct BitMap *BitMap;
  76.  
  77.     if(V39 && !Chip)
  78.         BitMap = AllocBitMap(Width,Height,Depth,BMF_MINPLANES,Friend);
  79.     else
  80.     {
  81.         struct FatBitMap *Fat;
  82.  
  83.         if(!(Fat = (struct FatBitMap *)AllocVec(sizeof(struct FatBitMap),MEMF_ANY | MEMF_PUBLIC | MEMF_CLEAR)))
  84.             BitMap = NULL;
  85.         else
  86.         {
  87.             LONG i;
  88.  
  89.             BitMap = (struct BitMap *)Fat;
  90.  
  91.             InitBitMap(BitMap,Depth,Width,Height);
  92.  
  93.             for(i = 0 ; i < Depth ; i++)
  94.             {
  95.                 if(!(BitMap->Planes[i] = AllocRaster(Width,Height)))
  96.                 {
  97.                     LONG j;
  98.  
  99.                     for(j = 0 ; j < i ; j++)
  100.                         FreeRaster(BitMap->Planes[j],Width,Height);
  101.  
  102.                     FreeVec(Fat);
  103.  
  104.                     return(NULL);
  105.                 }
  106.             }
  107.  
  108.             Fat->Width    = Width;
  109.             Fat->Height    = Height;
  110.  
  111.             if(Chip)
  112.             {
  113.                 ULONG Type = MEMF_CHIP;
  114.  
  115.                 for(i = 0 ; i < Depth ; i++)
  116.                     Type &= TypeOfMem(BitMap->Planes[i]);
  117.  
  118.                 if(!(Type & MEMF_CHIP))
  119.                 {
  120.                     LONG PageSize;
  121.  
  122.                     for(i = 0 ; i < Depth ; i++)
  123.                     {
  124.                         FreeRaster(BitMap->Planes[i],Width,Height);
  125.                         BitMap->Planes[i] = NULL;
  126.                     }
  127.  
  128.                     PageSize = BitMap->BytesPerRow * BitMap->Rows;
  129.  
  130.                     for(i = 0 ; i < Depth ; i++)
  131.                     {
  132.                         if(!(BitMap->Planes[i] = AllocVec(PageSize,MEMF_CHIP)))
  133.                         {
  134.                             LONG j;
  135.  
  136.                             for(j = 0 ; j < i ; j++)
  137.                                 FreeVec(BitMap->Planes[j]);
  138.  
  139.                             FreeVec(Fat);
  140.  
  141.                             return(NULL);
  142.                         }
  143.                     }
  144.  
  145.                     Fat->Width = Fat->Height = 0;
  146.                 }
  147.             }
  148.         }
  149.     }
  150.  
  151.     return(BitMap);
  152. }
  153.